function Jumppages(selector){
	this.ele = $(selector).get(0);
	$(this.ele).find('li').on({
		'click':function(){
			this.index=$(this).index();
			if(this.index==0){
				window.open("landingpage.html");
			}else if(this.index==1){
				window.open("registerpage.html");
			}else if(this.index==3){
				window.open("shopcat.html");
			}	
		}
	})
	
}

function Register(selector){
 	this.ele=$(selector).get(0);
 	this.username=$(this.ele).find('.main_username').get(0);
 	this.password1=$(this.ele).find('.main_password1').get(0);
 	this.password2=$(this.ele).find('.main_password2').get(0);
 	this.code=$(this.ele).find('.main_code').get(0);
 	this.a=1;
 	this.b=1;
 	this.c=1;
 	this.d=1;
 	this.Username();
 	this.Password();
 	this.Confirm();
 	this.Code();
 	this.Randomnum();
 	
 	
 	this.Skip();
 	this.Logmessage();

 }
Register.prototype.Username=function(){
	onself=this;
	$(this.username).on({
		'focus':function(){
			$(onself.username).css('border-color','#1a94d5');
			$(onself.ele).find('.pone').css('color','#ccc');
		},
		'blur':function(){
			$(onself.username).css('border-color','red');
			$(onself.ele).find('.pone').css('color','red');
			var str=$(onself.username).val();
			onself.a=1;
			var pattern =/^(\w)+(\.\w+)*@(\w)+((\.\w+)+)$/;
			var pattern1=/^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(18[05-9]))\d{8}$/;
			if(str==''){
				console.log(1)
			}else if(str.length<6){
				$(onself.ele).find('.pone').html('用户名不能少于6位');
			}else{
				if(pattern.test(str)==1||pattern1.test(str)==1){
					$(onself.ele).find('.main_img1').css('display','block');
					$(onself.ele).find('.pone').css('color','#fdfbf4');
					$(onself.username).css('border-color','#dbdbdb');
					onself.a=2;
				}else{
					$(onself.ele).find('.pone').html('请输入正确的手机号码或邮箱');
					$(onself.ele).find('.main_img1').css('display','none');		
					
				}
			}
			 
		},
	})
}
Register.prototype.Password=function(){
	onself=this;
	
	$(this.password1).on({
		'focus':function(){
			$(onself.password1).css('border-color','#1a94d5');
			$(onself.ele).find('.ptwo').css('color','#666').html('6~20位字母、数字或符号的组合');
		},
		'blur':function(){
			$(onself.password1).css('border-color','red');
			$(onself.ele).find('.ptwo').css('color','red');
			var str=$(onself.password1).val();
			onself.b=1;
			var pattern =/^[\d\D]{6,20}$/i;
			if(str==''){
				$(onself.ele).find('.ptwo').html('请输入密码')
				
			}else if(str.length<6&&str.length>20){
				$(onself.ele).find('.ptwo').html('密码长度只能在6～20位字符之间')
			}else{
				if(pattern.test(str)==1){
					$(onself.ele).find('.main_img2').css('display','block');
					$(onself.ele).find('.ptwo').css('color','#fdfbf4');
					$(onself.password1).css('border-color','#dbdbdb');
					onself.b=2;
				}else{
	
					$(onself.ele).find('.ptwo').html('密码长度只能在6～20位字符之间')
				
				}
			}
			 
		},
	})
}
Register.prototype.Confirm=function(){
	onself=this;
	
	$(this.password2).on({
		'focus':function(){
			$(onself.password2).css('border-color','#1a94d5');
			$(onself.ele).find('.pthree').css('color','#666').html('请再次输入密码')
		},
		'blur':function(){
				onself.c=1;
			$(onself.password2).css('border-color','red');
			$(onself.ele).find('.pthree').css('color','red');
			if($(onself.password2).val()==$(onself.password1).val()){
				console.log()
					$(onself.ele).find('.main_img3').css('display','block');
					$(onself.ele).find('.pthree').css('color','#fdfbf4');
					$(onself.password2).css('border-color','#dbdbdb');
					onself.c=2;
			}else{
				$(onself.ele).find('.pthree').html('两次密码不一致，请重新输入!');
				
			}
	
		},
	})
}
Register.prototype.Code=function(){
	onself=this;
	$(this.code).on({
		'focus':function(){
			$(onself.code).css('border-color','#1a94d5');
			$(onself.ele).find('.pfour').css('color','#666').html('请输入6位验证码')
		},
		'blur':function(){
			onself.d=1;
			$(onself.code).css('border-color','red');
			$(onself.ele).find('.pfour').css('color','red');
			if($(onself.code).val()==$(onself.ele).find('b').html()){
					$(onself.ele).find('.main_img4').css('display','block');
					$(onself.ele).find('.pfour').css('color','#fdfbf4');
					$(onself.code).css('border-color','#dbdbdb');
					onself.d=2;
			}else{
				$(onself.ele).find('.pfour').html('请重新输入!');
				onself.flag=true;
			}
	
		},
	})
}
Register.prototype.Randomnum=function(){
	var num=Math.ceil(Math.random()*9)*100000+Math.ceil(Math.random()*99999);
	$(this.ele).find('b').html(num);
	//console.log($(this.ele).find('b').html())
}


//跳转 
Register.prototype.Skip=function(){
	onself=this;
	$(onself.ele).find('.resetname').click(function(){
		location.replace("landingpage.html");
	})
}
Register.prototype.Logmessage=function(){
		onself=this;
				$('.landing').on({
					click:function(){
						if(onself.a==2&&onself.b==2&&onself.c==2&&onself.d==2){
							
							$.ajax({
								url:'../js/Register.php',
								//只要返回JSON数据的情况下，才需要设置这个属性
								dataType:'json',
								data:{
									username:$(onself.username).val(),
									password:$(onself.password1).val()
								},
								success:function(data){
									//显示后台返回的结果
									alert(data.content);
								},
								error:function(xhr){
									console.log(xhr.responseText);
//									alert(data.content);
									
								}
							})
						}else{
							alert('注册失败');
						}
						
					}
				})
}



//爬梯
function Scrolltop(selector) {
	this.ele = $(selector).get(0);
	this.up = $('.showup').get(0);
	this.mouseaction();
}
Scrolltop.prototype.mouseaction = function() {
		oself = this;
		var length = $(oself.up).find('li').size();
		$(oself.up).find(' li').on({
			'mouseenter mouseleave ': function() {

				this.index = $(this).index();
				if(this.index == 1) {
					$('.show').toggle();
				} 
			},
			'click': function() {
				oself = this;
				 if(oself.index == length - 1) {
					$(window).scrollTop(0)
				}else if(oself.index ==length - 2){
					window.open("shopcat.html");
				}

			}
		})
		$(window).scroll(function() {
			if($('html body').scrollTop() >200) {
//				
				$(oself.ele).css({'left':$(window).width()-60,'display':'block'})
			}else{
				$(oself.ele).css('display','none')
			}
		})
	}